#include<iostream>
#include<string>
using namespace std;

/*虚基类(virtual)
e.g A-->B1-->C
    A-->B2-->C
	A是虚基类
1.原理：多继承时发生了重名成员，且这些重名成员来自同一个间接基类，这个基类设置为虚基类
	    从不同路径继承过来的同名数据成员在内存中就只有一个拷贝，同一个函数名也只有一个映射
2.写法：class B1:public virtual A {};
		class B2:virtual public A {};
		virtual可以写在public前，也可以写在public后
3.子类构造：在存在虚基类时，对子类进行构造时，虚基类也要初始化
			即 子类构造函数(构造函数参数):虚基类(参数),基类1(参数),基类2(参数){}
4.构造函数调用顺序：虚基类 --> 非虚基类 --> 成员对象 --> 派生类自己
【注】引用虚基类的函数时，正常引用就可以
*/

/*class Person{
	string name;
	string ID;
public:
	Person(string n, string id){
		name = n;
		ID = id;
		cout << "构造Person" << endl;
	}
	void pshow() { cout << name << "  " << ID << "  "; }
};

class Student:virtual public Person{
	double sorce;
public:
	Student(string n, string id, double s):Person(n, id){
		sorce = s;
		cout << "构造Student" << endl;
	}
	void sshow() { cout << sorce << "  "; }
};

class Teacher:public virtual Person{
	double wage;
public:
	Teacher(string n, string id, double w):Person(n, id){
		wage = w;
		cout << "构造Teacher" << endl;
	}
	void tshow() { cout << wage << "  "; }
};

class ST:public Student, public Teacher{
	string data;
public:
	ST(string n, string id, double s, double w, string d):Person(n, id), Student(n, id, s), Teacher(n, id, w){
		data = d;
		cout << "构造ST" << endl;
	}
	void stshow(){
		pshow();
		sshow();
		tshow();
		cout << data << endl;
	}
};

int main()
{
	ST st1("zhangsan", "230001", 79.2, 5000.0, "2024.3.10");
	st1.stshow();

	return 0;
}*/

/*class A{
public:
	int id;
	void fun(){ cout << "A" << endl; }
};
class B1:public A { public: int b1; };
class B2:public A { public: int b2; };
class C:public B1, public B2{
public:
	int c;
};

int main()
{
	C obj;
	obj.c = 20;
	obj.b1 = 10;
	obj.b2 = 30;
	
	obj.B1::id = 12;
	obj.B2::id = 18;
	
	obj.B1::fun();
	obj.B2::fun();
	
	return 0;
}*/

/*同名覆盖 --- 变量的同名/函数的同名(函数头完全相同)
1.当子类中出现与父类同名的成员，父类成员被覆盖
2.父类中与子类同名的成员仍然存在，只是在调用时需要明确指出是父类的成员
e.g 子类对象.父类::成员
*/

/*class A{
public:
	int k;
	void fun(){ cout << "AAAAA" << endl; }
};

class B:public A{
public:
	int k;
	void fun(){ cout << "BBBBB" << endl; }
};

int main()
{
	B obj;
	obj.k = 29; //此处的k是B类的成员k
	obj.fun(); //此处的fun函数指B类的fun函数
	
	obj.A::k = 33;
	obj.A::fun();
	
	return 0;
}*/

/*class B1{
public:
	int k;
};

class B2{
public:
	int k;
};

class C:public B1, public B2{
public:
	void fun(){ B1::k = 13; }
};*/
